import java.util.Comparator;
import java.util.Objects;
import java.util.concurrent.Callable;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-04-22
 * Time: 21:57
 */
class Card implements Comparable<Card> {

    public String suit;
    public int rang;

    public Card(String suit, int rang) {
        this.suit = suit;
        this.rang = rang;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Card card = (Card) o;
        return rang == card.rang && Objects.equals(suit, card.suit);
    }

    @Override
    public int hashCode() {
        return Objects.hash(suit, rang);
    }

    @Override
    public String toString() {
        return "Card{" +
                "suit='" + suit + '\'' +
                ", rang=" + rang +
                '}';
    }

    @Override
    public int compareTo(Card o) {
        return this.rang - o.rang;
    }
}

class SuitCmp implements Comparator<Card> {

    @Override
    public int compare(Card o1, Card o2) {
        return o1.suit.compareTo(o2.suit);
    }
}
public class Test {
    /**
     * equals返回值是布尔类型，判断两个对象是否相同
     * comparable 和 comparator返回值是整形，可以比较大小
     * 本身区别就在于前者一般在当前类中使用，另一个是脱离当前类来使用
     *
     * @param args
     */
    public static void main(String[] args) {
        Card card1 = new Card("heitao", 8);
        Card card2 = new Card("hongtao",9);

        //比较牌的数字的大小
        int ret = card1.compareTo(card2);
        if(ret > 0){
            System.out.println("card1 > card2");
        }else {
            System.out.println("card1 < card2");
        }

        //比较牌色的大小
        SuitCmp suitCmp = new SuitCmp();
        int ret2 = suitCmp.compare(card1, card2);
        if(ret > 0){
            System.out.println("card1 > card2");
        }else {
            System.out.println("card1 < card2");
        }
    }

    public static void main1(String[] args) {
        Card card1 = new Card("heitao", 8);
        Card card2 = new Card("heitao", 8);

        System.out.println(card1.equals(card2));

    }
}